import { IContextState } from './interface';
export const inital: IContextState = {
    width: 0,
    height: 0,
    image: { el: null, width: 0, height: 0 },
    viewer: null,
    magnifyPoint: {
        x: 0,
        y: 0,
        right: 0,
        bottom: 0
    },
    action: null,
    stack: [],
    cursor: null
}
export const reducer: any = (state: IContextState, action: any) => {
    console.log(action)
    switch (action.type) {
        case 'init':
            return { ...state, ...action.data }
        case 'setImage':
            return { ...state, image: action.data }
        case 'setViewer':
            return { ...state, viewer: action.data }
        case 'setMagnifyPoint':
            return { ...state, magnifyPoint: action.data }
        case 'reset':
            return {
                ...state, 
                viewer: null, 
                magnifyPoint: {
                    x: 0,
                    y: 0,
                    right: 0,
                    bottom: 0
                }
            }
        case 'resizing':
            return {
                ...state,
                viewer: {
                    ...state.viewer,
                    resizing: true
                }
            }
        case 'setState':
            return {
                ...state,
                ...action.data
            }
        default:
            return { ...inital }
    }
}